//
//  HJPersonalCenterV2Controller.m
//  KaiChat
//
//  Created by lx on 2024/1/16.
//

#import "HJPersonalCenterV2Controller.h"
#import "HJTitleCell.h"
#import "HJModifyNicknameController.h"
#import "HJModifyIntroduceController.h"
#import "HJModifyUIDController.h"
#import "HJUserModel.h"
#import "HJModifyGenderController.h"
#import "HJMinePresent.h"
#import "HJPersonalAvatarController.h"
#import "HJSetBirthdayController.h"
#import "HJRegionController.h"
#import "QMUITextField.h"
#import "QMUITextView.h"

@interface HJPersonalCenterV2Controller ()<QMUITextFieldDelegate, QMUITextViewDelegate>

@property (nonatomic, strong) NSArray *datas;
@property (nonatomic, strong) HJUserModel *userModel;
@property (nonatomic, weak) HJBarButton *doneButton;
@property (nonatomic, weak) UIView *contentView;
@property (nonatomic, weak) UIView *profileView;
@property (nonatomic, weak) QMUITextField *nicknameTextField;
@property (nonatomic, assign) NSInteger nameMaxLenght;
@property (nonatomic, assign) NSInteger profileViewMaxLenght;
@property (nonatomic, strong) QMUITextView *profileViewTextView;
@property (nonatomic, assign) CGFloat textView_Height_Max;
@property (nonatomic, assign) CGFloat textView_Height_Min;
@property (nonatomic, assign) CGFloat textView_topMargin;
@property (nonatomic, weak) UIView *headerView;
@property (nonatomic, weak) UILabel *profileLengthLabel;
@property (nonatomic, weak) UILabel *nameLengthLabel;
@property (nonatomic, assign) BOOL isModify;
@property (nonatomic, assign) BOOL viewDidLoadIsFinish;
@property (nonatomic, weak) UIImageView *avatarImageView;

@end

@implementation HJPersonalCenterV2Controller

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.nameMaxLenght = 20;
    self.profileViewMaxLenght = 600;
    self.textView_Height_Min = 46;
    self.textView_Height_Max = 80;
    
    self.navigationBar.alpha = 0;
    
    self.userModel = [HJUserModel currentAccountModel];
    
    HJBarButton *doneButton = [HJBarButton barButtonWithTitle:@"Done" color:UIColor.tj_mainColor target:self action:@selector(didClickDoneButton)];
    [doneButton setTitleColor:UIColor.tj_BEBDCAColor forState:UIControlStateDisabled];
    doneButton.enabled = NO;
    [doneButton sizeToFit];
    CGSize doneButtonSize = doneButton.tj_size;
    [self.navigationBar.contentView addSubview:doneButton];
    [doneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(leftRightMargin);
        make.width.offset(doneButtonSize.width);
        make.height.offset(40);
        make.centerY.offset(0);
    }];
    _doneButton = doneButton;
    
    UIScrollView *scrollView = [UIScrollView addToView:self.view];
    scrollView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
    scrollView.backgroundColor = UIColor.tj_backgroundColor;
    CGSize contentSize = scrollView.bounds.size;
    scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    scrollView.contentSize = contentSize;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.alwaysBounceVertical = YES;
    scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    
    UIView *contentView = [[UIView alloc] init].addTo(scrollView);
    contentView.backgroundColor = UIColor.tj_backgroundColor;
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
        make.width.offset(contentSize.width);
        make.height.offset(contentSize.height);
    }];
    
    UIImageView *topBackgroundImageView = [UIImageView addToView:contentView];
    topBackgroundImageView.image = [UIImage imageNamed:@"mine_top_bg"];
    [topBackgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
    }];
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, KNavBarHight + 27, KScreenWidth, 248)];
    headerView.layer.mask = [headerView shapeLayerRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight radius:20];
    headerView.backgroundColor = UIColor.whiteColor;
    [contentView addSubview:headerView];
    
    UIView *nicknameView = [self addNicknameView];
    [headerView addSubview:nicknameView];
    nicknameView.frame = CGRectMake(leftRightMargin, 58, KScreenWidth - leftRightMargin * 2, 75);
    
    UIView *profileView = [self addProfileView];
    [headerView addSubview:profileView];
    profileView.frame = CGRectMake(leftRightMargin, CGRectGetMaxY(nicknameView.frame) + 20, KScreenWidth - leftRightMargin * 2, 75);
    
    UIView *lineView = [UIView addToView:headerView];
    lineView.backgroundColor = UIColor.tj_separatorColor;
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(leftRightMargin);
        make.bottom.inset(1);
        make.height.offset(lineHeight);
    }];
    
    [self.tableView removeFromSuperview];
    [contentView addSubview:self.tableView];
    self.view.backgroundColor = UIColor.whiteColor;
    self.tableViewStyle = UITableViewStylePlain;
    [self.tableView registerClass:HJTitleCell.class forCellReuseIdentifier:@"HJTitleCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = cellHeight;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.bounces = NO;
    self.tableView.scrollEnabled = NO;
    self.tableView.backgroundColor = UIColor.whiteColor;
    
    CGFloat tableViewH = self.datas.count * cellHeight;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(headerView.mas_bottom).offset(0);
        make.height.offset(tableViewH);
    }];
    
    UIImageView *avatarImageView = [UIImageView addToView:contentView];
    avatarImageView.addCornerRadius(45);
    [avatarImageView addTapGesturesWithTarget:self action:@selector(didClickAvatarImageView)];
    avatarImageView.userInteractionEnabled = YES;
    [avatarImageView tj_setImageWithURL:HJUserInfo.avatar.URL placeholderImage:[UIImage imageNamed:@"avatar"]];
    [avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.width.height.offset(90);
        make.top.offset(KStatusBarHight + 20);
    }];
    
    UIButton *editButton = [UIButton addToView:contentView];
    [editButton setImage:[UIImage imageNamed:@"avatar_edit"] forState:UIControlStateNormal];
    [editButton setImage:[UIImage imageNamed:@"avatar_edit"] forState:UIControlStateHighlighted];
    [editButton addTarget:self action:@selector(didClickAvatarImageView) forControlEvents:UIControlEventTouchUpInside];
    [editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(avatarImageView);
        make.bottom.equalTo(avatarImageView);
        make.width.height.offset(22);
    }];
    
    [self.view setNeedsLayout];
    [self.view layoutIfNeeded];
    
    [self updateNickNameLengthLabelText];
    [self updateProfileLengthLabelText];
    
    _headerView = headerView;
    _nicknameTextField.text = _userModel.nickname;
    _profileViewTextView.text = _userModel.whatsUp;
    _avatarImageView = avatarImageView;
    
    CGFloat contentHeight = _profileViewTextView.contentSize.height;
    CGPoint bottomOffset = CGPointMake(0, contentHeight - _profileViewTextView.bounds.size.height);
    [_profileViewTextView setContentOffset:bottomOffset animated:NO];
    
    self.viewDidLoadIsFinish = YES;
}

- (UIView *)addNicknameView {
    
    UIView *nicknameView = [[UIView alloc] init];
    
    UILabel *titleLabel = [UILabel lableWithSuperView:nicknameView font:UIFontMediumMake(14) color:UIColor.tj_333333Color title:@"Nickname" textAlignment:NSTextAlignmentLeft];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(0);
    }];
    
    UIView *textFieldContentView = [UIView addToView:nicknameView];
    textFieldContentView.addCornerRadius(10);
    textFieldContentView.backgroundColor = UIColor.tj_F6F6F6Color;
    [textFieldContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(0);
        make.bottom.offset(0);
        make.height.offset(46);
    }];
    
    QMUITextField *textField = [QMUITextField addToView:textFieldContentView];
    textField.font = UIFontMake(14);
    textField.delegate = self;
    textField.placeholder = @"Your nickname";
    textField.maximumTextLength = 20;
    textField.banEnterChinese = YES;
    textField.tintColor = UIColor.tj_cursorColor;
    textField.returnKeyType = UIReturnKeyDone;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField.textColor = UIColor.tj_1A1A1AColor;
    [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.inset(60);
        make.top.bottom.offset(0);
    }];
    
    UILabel *nameLengthLabel = [UILabel lableWithSuperView:nicknameView font:UIFontMake(12) color:UIColor.tj_BEBDCAColor title:nil textAlignment:NSTextAlignmentLeft];
    [nameLengthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(15);
        make.centerY.equalTo(textFieldContentView);
    }];
    
    _nicknameTextField = textField;
    _nameLengthLabel = nameLengthLabel;
    return nicknameView;
}

- (UIView *)addProfileView {
    
    UIView *profileView = [[UIView alloc] init];
    
    UILabel *titleLabel = [UILabel lableWithSuperView:profileView font:UIFontMediumMake(14) color:UIColor.tj_333333Color title:@"Profile" textAlignment:NSTextAlignmentLeft];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(0);
    }];
    
    _profileViewTextView = [[QMUITextView alloc] init];
    _profileViewTextView.placeholder = @"Friends can view your profile";
    _textView_topMargin = (_textView_Height_Min - ceilf(UIFontMake(14).lineHeight)) * 0.5;
    _profileViewTextView.textContainerInset = UIEdgeInsetsMake(_textView_topMargin, 10, _textView_topMargin, 80);
    [_profileViewTextView setFont:UIFontMake(14)];
    _profileViewTextView.placeholderColor = UIColor.tj_placeholderTextColor;
    _profileViewTextView.frame = CGRectMake(0, 30, KScreenWidth - leftRightMargin * 2, _textView_Height_Min);
    _profileViewTextView.tintColor = UIColor.tj_cursorColor;
    _profileViewTextView.backgroundColor = UIColor.tj_F6F6F6Color;
    _profileViewTextView.textColor = UIColor.tj_333333Color;
    _profileViewTextView.maximumTextLength = _profileViewMaxLenght;
    _profileViewTextView.addCornerRadius(10);
    [profileView addSubview:_profileViewTextView];
    
    UILabel *profileLengthLabel = [UILabel lableWithSuperView:profileView font:UIFontMake(12) color:UIColor.tj_BEBDCAColor title:nil textAlignment:NSTextAlignmentLeft];
    [profileLengthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(15);
        make.bottom.inset(15);
    }];
    
    _profileLengthLabel = profileLengthLabel;
    _profileView = profileView;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTextChanged:) name:UITextViewTextDidChangeNotification object:_profileViewTextView];
    
    return profileView;
}


- (BOOL)textField:(QMUITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    // 获取新的文本
    NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:string];
    // 去除字符串开头和结尾的空格
    NSString *trimmedString = [newText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    // 判断新的文本与去除空格后的文本是否相等，如果不相等，则说明用户尝试在开头或结尾输入空格
    if (![newText isEqualToString:trimmedString]) {
        // 如果是空格，则不允许输入
        if ([string isEqualToString:@" "]) {
            return NO;
        } else if ([string isEqualToString:@""] && range.length > 0) {// 如果是删除操作，且删除的是开头或结尾的空格，则允许删除
            return YES;
        } else { // 其他情况，不允许输入
            return NO;
        }
    }
    // 允许输入其他字符
    return YES;
}

- (void)textFieldDidChange:(QMUITextField *)textField {
    if (self.viewDidLoadIsFinish) {
        self.isModify = YES;
    }
    [self updateDoneButtonState];
    [self updateNickNameLengthLabelText];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

- (void)updateNickNameLengthLabelText {
    
    if ( _nicknameTextField.text.length > 0) {
        _nameLengthLabel.attributedText = [[NSString stringWithFormat:@"%ld/%ld", _nicknameTextField.text.length, _nameMaxLenght] attributedStringWithRangeString:[NSString stringWithFormat:@"%ld", _nicknameTextField.text.length] rangeColor:UIColor.tj_333333Color color:UIColor.tj_868391Color];
    } else {
        _nameLengthLabel.attributedText = [[NSString stringWithFormat:@"%ld/%ld", _nicknameTextField.text.length, _nameMaxLenght] attributedStringWithRangeString:[NSString stringWithFormat:@"%ld", _nicknameTextField.text.length] rangeColor:UIColor.tj_868391Color color:UIColor.tj_868391Color];
    }
}


- (void)updateProfileLengthLabelText {
    if ( _profileViewTextView.text.length > 0) {
        _profileLengthLabel.attributedText = [[NSString stringWithFormat:@"%ld/%ld", _profileViewTextView.text.length, _profileViewMaxLenght] attributedStringWithRangeString:[NSString stringWithFormat:@"%ld", _profileViewTextView.text.length] rangeColor:UIColor.tj_333333Color color:UIColor.tj_868391Color];
    } else {
        _profileLengthLabel.attributedText = [[NSString stringWithFormat:@"%ld/%ld", _profileViewTextView.text.length, _profileViewMaxLenght] attributedStringWithRangeString:[NSString stringWithFormat:@"%ld", _profileViewTextView.text.length] rangeColor:UIColor.tj_868391Color color:UIColor.tj_868391Color];
    }
    
}

- (void)handleTextChanged:(NSNotification *)not {
    NSLog(@"not.object = %@", not.object);
    if (not.object != _profileViewTextView) return;
    
    if (self.viewDidLoadIsFinish) {
        self.isModify = YES;
    }
    
    [self updateProfileLengthLabelText];
    [self updateDoneButtonState];
    [self updataTextViewHeight];
}

- (BOOL)textViewShouldReturn:(QMUITextView *)textView {
    [self.view endEditing:YES];
    return YES;
}
- (void)updataTextViewHeight {
    
    CGSize size = [_profileViewTextView sizeThatFits:CGSizeMake(_profileViewTextView.frame.size.width, _textView_Height_Max)];
    CGFloat oldHeight = _profileViewTextView.frame.size.height;
    CGFloat newHeight = size.height;
    
    if(newHeight > _textView_Height_Max){
        newHeight = _textView_Height_Max;
    }
    if(newHeight < _textView_Height_Min){
        newHeight = _textView_Height_Min;
    }
    if(oldHeight == newHeight){
        return;
    }
    
    CGRect textFrame = self.profileViewTextView.frame;
    textFrame.size.height += newHeight - oldHeight;
    self.profileViewTextView.frame = textFrame;
    [self layoutButton:newHeight + 2 * self.textView_topMargin];
}

- (void)layoutButton:(CGFloat)height {
    CGRect frame = self.profileView.frame;
    frame.size.height = height;
    self.profileView.frame = frame;
    
    CGRect headerViewFrame = self.headerView.frame;
    headerViewFrame.size.height = 58 + 75 + 40 + height;
    self.headerView.frame = headerViewFrame;
    self.headerView.layer.mask = [self.headerView shapeLayerRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight radius:20];
    
}

- (void)updateDoneButtonState {
    _doneButton.enabled =  _isModify && !isEmptyString(_nicknameTextField.text);
}


- (void)didClickDoneButton {
    
    [self.view endEditing:YES];
    
    [HJHUD showLoadingInView:self.view];
    [HJMinePresent modifyProfile:_profileViewTextView.text nickname:_nicknameTextField.text complete:^(NSError * _Nullable error) {
        if (error) {
            [HJHUD showErrorMessageTip];
            return;
        }
        
        self.userModel.whatsUp = self.profileViewTextView.text;
        self.userModel.nickname = self.nicknameTextField.text;
        [self.userModel bg_saveOrUpdateAsync:nil];
        if (self.popBlock) {
            self.popBlock();
        }
        [self.navigationController popViewControllerAnimated:YES];
        
        [HJHUD showSucceedMessage:@"Successful operation"];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HJCellModel *model = _datas[indexPath.row];
    HJTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HJTitleCell" forIndexPath:indexPath];
    cell.model = model;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    HJCellModel *model = self.datas[indexPath.row];
    TJWeakify(self)
    if ([model.identifier isEqualToString:@"nickname"]) {
        HJModifyNicknameController *modifyNicknameController = [[HJModifyNicknameController alloc] init];
        [modifyNicknameController setComplete:^{
            model.detailText = HJUserInfo.nickname;
            [weakself.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }];
        [modifyNicknameController showInController:self];
        return;
    }
    
    if ([model.identifier isEqualToString:@"whatsUp"]) {
        HJModifyIntroduceController *modifyIntroduceController = [[HJModifyIntroduceController alloc] init];
        modifyIntroduceController.whatsUp = self.userModel.whatsUp;
        [modifyIntroduceController setComplete:^(NSString *value){
            model.detailText = value;
            weakself.userModel.whatsUp = value;
            NSString *whatsUp = self.userModel.whatsUp;
            if (whatsUp.length == 0) {
                model.detailText = @"Briefly introduce yourself...";
            } else {
                model.detailText = whatsUp;
            }
            [weakself.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }];
        [self.navigationController pushViewController:modifyIntroduceController];
        return;
    }
    
    if ([model.identifier isEqualToString:@"UID"]) {
        HJModifyUIDController *modifyUIDController = [[HJModifyUIDController alloc] init];
        modifyUIDController.userModel = self.userModel;
        [modifyUIDController setComplete:^(NSString *value){
            model.detailText = value;
            [weakself.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
            [weakself loadData];
        }];
        [self.navigationController pushViewController:modifyUIDController];
        return;
    }
    
    if ([model.identifier isEqualToString:@"gender"]) {
        HJModifyGenderController *modifyGenderController = [[HJModifyGenderController alloc] init];
        modifyGenderController.type = model.detailText;
        [modifyGenderController setComplete:^(HJCellModel *cellModel){
            weakself.userModel.gender = cellModel.anyObject;
            model.detailText = cellModel.text;
            model.detailTextColor = UIColor.tj_868391Color;
            [weakself.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }];
        [self presentViewController:modifyGenderController animated:NO completion:nil];
        return;
    }
    
    if ([model.identifier isEqualToString:@"birthday"]) {
        HJSetBirthdayController *setBirthdayController = [[HJSetBirthdayController alloc] init];
        setBirthdayController.date = self.userModel.birthday;
        [setBirthdayController setComplete:^(NSString * _Nonnull value) {
            weakself.userModel.birthday = value;
            model.detailText = value;
            model.detailTextColor = UIColor.tj_868391Color;
            [weakself.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }];
        [self presentViewController:setBirthdayController animated:NO completion:nil];
        return;
    }
    
    if ([model.identifier isEqualToString:@"region"]) {
        HJRegionController *regionController = [[HJRegionController alloc] init];
        regionController.region = self.userModel.region;
        [regionController setComplete:^(NSString * _Nonnull value) {
            weakself.userModel.region = value;
            model.detailText = value;
            model.detailTextColor = UIColor.tj_868391Color;
            [weakself.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }];
        [self.navigationController pushViewController:regionController];
        return;
    }
    
    if ([model.identifier isEqualToString:@"QRCode"]) {
        [self.navigationController pushViewControllerWithName:@"HJQrCodeController"];
        return;
    }
    
}

- (void)didClickAvatarImageView {
    TJWeakify(self)
    HJPersonalAvatarController *personalAvatarController = [[HJPersonalAvatarController alloc] init];
    [personalAvatarController setComplete:^(NSString * _Nonnull value) {
        weakself.userModel.avatar = value;
        [weakself.avatarImageView tj_setImageWithUrl:value];
        HJUserModel *userModel = [HJUserModel currentAccountModel];
        userModel.avatar = value;
        [userModel bg_saveOrUpdateAsync:nil];
    }];
    [self.navigationController pushViewController:personalAvatarController];
}

- (void)loadData {
    [HJMinePresent loadUserInfoComplete:^(HJUserModel * _Nullable userModel) {
        self.userModel = userModel;
        self.datas = nil;
        [self.tableView reloadData];
    }];
}

- (NSArray *)datas {
    if (!_datas) {
        _datas = @[
            [HJCellModel modelWithBlock:^(HJCellModel * _Nonnull model) {
                model.text = @"Gender";
                model.detailText = @"Not Set";
                model.identifier = @"gender";
                NSInteger gender = [self.userModel.gender intValue];
                if (gender == 0) {
                    model.detailText = @"Not Set";
                    model.detailTextColor = UIColor.tj_BEBDCAColor;
                } else if (gender == 1) {
                    model.detailText = @"Male";
                    model.detailTextColor = UIColor.tj_868391Color;
                } else if (gender == 2) {
                    model.detailText = @"Female";
                    model.detailTextColor = UIColor.tj_868391Color;
                } else {
                    model.detailText = @"Secrecy";
                    model.detailTextColor = UIColor.tj_868391Color;
                }
            }],
            [HJCellModel modelWithBlock:^(HJCellModel * _Nonnull model) {
                model.text = @"Birthday";
                model.identifier = @"birthday";
                NSString *birthday = self.userModel.birthday;
                if (isEmptyString(birthday)) {
                    model.detailText = @"Not Set";
                    model.detailTextColor = UIColor.tj_BEBDCAColor;
                } else {
                    model.detailText = birthday;
                    model.detailTextColor = UIColor.tj_868391Color;
                }
            }],
            [HJCellModel modelWithBlock:^(HJCellModel * _Nonnull model) {
                model.text = @"Region";
                model.identifier = @"region";
                NSString *region = self.userModel.region;
                if (isEmptyString(region)) {
                    model.detailText = @"Not Set";
                    model.detailTextColor = UIColor.tj_BEBDCAColor;
                } else {
                    model.detailText = region;
                    model.detailTextColor = UIColor.tj_868391Color;
                }
            }],
            [HJCellModel modelWithBlock:^(HJCellModel * _Nonnull model) {
                model.text = @"QR Code";
                model.identifier = @"QRCode";
                model.detailTextColor = UIColor.tj_868391Color;
                model.detailText = @"Your QR Code";
            }],
            [HJCellModel modelWithBlock:^(HJCellModel * _Nonnull model) {
                model.text = @"UID";
                model.identifier = @"UID";
                model.detailText = self.userModel.uid;
                model.detailTextColor = UIColor.tj_868391Color;
            }]
        ];
    }
    return _datas;
}

- (void)dealloc {
    if (self.popBlock) {
        self.popBlock();
    }
    NSLog(@"%s", __func__);
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end

